package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInvoker extends DefaultInvoker {
    public boolean doBefore() {
        return false;
    }

    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            String inputPw = request.getParameter("pw");
            if (Utils.isEmpty(inputPw) || !inputPw.equals(PW)) {
                response.sendRedirect(SHELL_NAME + "?o=vLogin");
                return;
            } else {
                session.setAttribute(PW_SESSION_ATTRIBUTE, inputPw);
                response.sendRedirect(SHELL_NAME + "?o=index");
                return;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}